package main

import (
	"fmt"
	"os"
	"os/exec"
	"runtime"
	"strings"
)

func main() {
	// 输出Go的版本
	fmt.Printf("Go Version: %s\n", runtime.Version())

	// 获取并输出GOROOT环境变量
	goroot := runtime.GOROOT()
	fmt.Printf("GOROOT: %s\n", goroot)

	// 在Unix-like系统（包括Linux和macOS）上获取并输出GOPATH
	// 对于Go 1.13+，也可以尝试获取GO111MODULE和GOPROXY等环境变量
	gopath := os.Getenv("GOPATH")
	if gopath != "" {
		fmt.Printf("GOPATH: %s\n", gopath)
	} else {
		fmt.Println("GOPATH is not set or empty (in Go 1.13+, GOPATH might be implicitly set based on GO111MODULE)")
	}

	// 在终端执行"go env"命令来获取更多详细的环境配置
	cmd := exec.Command("go", "env")
	output, err := cmd.Output()
	if err == nil {
		envDetails := strings.TrimSpace(string(output))
		fmt.Printf("\nDetailed Go Environment Configuration:\n%s\n", envDetails)
	} else {
		fmt.Printf("Error running 'go env': %v\n", err)
	}
}
